<template>
  <div>
    <el-table
      :data="menList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="scoped">
          <div>
            <i :class="scoped.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-if="scoped.row.status == 2"
              >禁用</el-button
            >
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button @click="bj(scoped.row.id)" type="primary"
              >编辑</el-button
            >
            <el-button @click="del(scoped.row.id)" type="warning"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { menudelete } from "../../../request/api.js";
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      sss: "menuList/asyncChangeList",
    }),
    del(id) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          menudelete({ id: id }).then((res) => {
            if (res.data.code == 200) {
              successAlert(res.data.msg);
              this.sss();
            } else {
              warningAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          warningAlert("已取消删除");
        });
    },
    bj(id) {
      this.$emit("aa", id);
    },
  },
  computed: {
    ...mapGetters({
      menList: "menuList/list",
    }),
  },

  mounted() {
    this.sss();
  },
};
</script>

<style lang="scss" scoped>
</style>